<?php

namespace app\api\controller;

use app\api\service\UserToken;
use app\api\validate\TokenValidate;
use app\api\service\Token as TokenService;

class Token extends Common
{
    /**
     * 校验Token
     * @param string $token
     * @return \think\response\Json
     * @throws \app\lib\exception\ThrowError
     */
    public function verifyToken($token = '')
    {
        if (!$token)
        {
            T(600001);
        }

        $valid = TokenService::verifyToken($token);
        return $this->response(['isValid' => $valid]);
    }

    /**
     * 获取用户Token
     * @param string $code
     * @return \think\response\Json
     * @throws \app\lib\exception\ThrowError
     * @throws \think\Exception
     */
    public function getUserToken($code = '')
    {
        (new TokenValidate('getUserToken'))->goCheck();
        $token = new UserToken($code);
        $token = $token->get();
        return $this->response(['token' => $token]);
    }
}
